<?php 
/*
 * Session variables:
 * 'database' [string] = database name of the current tutorial centre
 * 'type' [string] = user type of the logged in user
 * 'authorised' [boolean] = whether or not the current user is logged in
 * 'user' [string] = the username/ email of the logged in user 
 */

session_start();

if(isset($_SESSION['authorised']) && $_SESSION['authorised'] == true)
{
	if(isset($_SESSION['type']))
	{
		if($_SESSION['type'] == 'administrator')
		{
			header('Location: adminindex.php');
			exit();
		}
		elseif($_SESSION['type'] == 'student')
		{
			$host = 'localhost';
			$dbuser = 'postgres';
			$dbpass = 'password';
			$dbname = $_SESSION['database'];
			
			pg_connect("host=$host user=$dbuser password=$dbpass dbname=$dbname") or die(pg_last_error());
			
			$sql = "SELECT * FROM announcements;";
			$result = pg_query($sql);
			
			
			
			?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Home</title>
<link href="StyleSheet.css" rel="stylesheet" type="text/css" />
<style>
.nav {
	width: 210px;
	height: auto;
	border: thin solid #09C;
	margin-left: 10px;
	text-align: center;
}

.mainline {
	width: 712px;
	height: auto;
	text-align: center;
}
</style>
</head>
<body bgcolor="#FFFFFF">
	<center>

		<div id="wrapper">
			<div id="header">
				<h1></h1>
			</div>

			<div id="header2">
				<h3></h3>
			</div>

			<div id="nav">
				<h4>Navigation</h4>
				<b style="color:#069">Tutorial Centre:</b><br />
				<?php echo $_SESSION['tcentre'];?><br /><br />
				<b style="color:#069">Account Name:</b><br />
				<?php echo $_SESSION['user'];?><br /><br />
				<b style="color:#069">Account Type:</b><br />
				<?php echo $_SESSION['type'];?><br /><br />
				<center>
					<script src="studentjs.js" type="text/javascript"></script>
					<noscript>
						<OBJECT id="studentobj"
							classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
							codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0"
							WIDTH=230 HEIGHT=200>
							<PARAM NAME=movie VALUE="student.swf">
							<PARAM NAME=menu VALUE=false>
							<PARAM NAME=quality VALUE=high>
							<PARAM NAME=wmode VALUE=opaque>
							<param name="scale" value="noscale" />
							<PARAM NAME=bgcolor VALUE=#FFFFFF>
							<EMBED src="student.swf" menu=false quality=high scale="noscale"
								wmode=opaque bgcolor=#FFFFFF WIDTH=230 HEIGHT=200
								TYPE="application/x-shockwave-flash"
								PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">
							</EMBED>
						</OBJECT>
					</noscript>
				</center>
			</div>

			<div id="mainline">
				<h4>Welcome Student</h4>
				<div id="body">
					<h1>Tutorial News</h1>
					<div align="justify"></div>
					<table width="600">
						<tr>
							<th align="left">Date</th>
							<th align="left">Announcement</th>
						</tr>
						<?php 
						for ($i = 0; $i < pg_num_rows($result); $i++) {
							$announcement_date = pg_fetch_result($result, $i, 'announcement_date');
							$announcement = pg_fetch_result($result, $i, 'announcement');
							echo "<tr><td>$announcement_date</td><td>$announcement</td></tr>";	
						}
						?>
					</table>
				</div>
			</div>

			<br class="clearfloat"> <br />

			<div id="footer">
				<p align="center">
					Tutorial Business Manager: info@tbms.com <br />Credits/Engineers:
					Aquino, Chloebelle; Dela Cruz, Roy Erwin; Maliwanag, Ranyel Bryan;
					Manzano, Audrey Ann; Ng, Sheila Regine<br /> <br />copyright 2011
				</p>
			</div>
		</div>
	</center>
</body>
</html>
			<?php
		}
		elseif($_SESSION['type'] == 'tutor')
		{
			header('Location: tutorindex.php');
			exit();
		}
		elseif($_SESSION['type'] == 'parent')
		{
			header('Location: parentindex.php');
			exit();
		}
	}
}
else
{
	header('Location: index.php');
}
?>
